<template>
  <div>
    <el-row :gutter="20">
       <el-col :span="6">
        <div class="form-item">
          <span class="title">商品名称</span>
          <el-input placeholder="请输入名称" v-model="param.data.skuName"></el-input>
        </div>
      </el-col>
      <el-col :span="6">
        <div class="form-item">
          <span class="title">创建日期</span>
          <el-date-picker
            v-model="createdateList"
            type="daterange"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :clearable="false"
          ></el-date-picker>
        </div>
      </el-col>
      <el-col :span="6">
        <div class="form-item button-container">
          <el-button type="primary" @click="search" icon="el-icon-search">查询</el-button>
          <el-button type="primary" @click="resetSearchCotnet" icon="el-icon-refresh">重置</el-button>
        </div>
      </el-col>
    </el-row>

    <div class="table-body">
      <el-table :data="tableData" border v-loading="isLoading" style="width: 100%">
        <el-table-column prop="createTime" label="创建时间"></el-table-column>
        <el-table-column prop="storageTime" label="入库时间"></el-table-column>
        <el-table-column prop="skuName" label="商品名称"></el-table-column>
        <el-table-column prop="num" label="入库数量"></el-table-column>
        <el-table-column prop="remark" label="备注"></el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination
          background
          @current-change="currentPageChange"
          layout="prev, pager, next"
          :total="total"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "",
  data() {
    return {
      param: {
        data: {
          skuName: "",
          stTime: "",
          byTime: ""
        },
        queryRequest: {
          pageNum: 1,
          pageSize: 10
        }
      },

      createdateList: [],
      tableData: [],
      isLoading: true,
      total: 1
    };
  },
  components: {},
  computed: {},
  beforeMount() {},
  mounted() {
    this.initData();
  },
  methods: {
    initData() {
      this.isLoading = true;
      if (this.createdateList.length > 0) {
        this.param.data.stTime = this.createdateList[0];
        this.param.data.byTime = this.createdateList[1];
      }
      this.$service.selectEnter(this.param).then(res => {
        this.isLoading = false;
        if (res.code == "00000") {
           if (
            res.data.rows.length == 0 &&
            this.param.queryRequest.pageNum != 1
          ) {
            this.param.queryRequest.pageNum -= 1;
            this.initData();
          }
          this.tableData = res.data.rows;
          this.total = res.data.total || 0;
        }
      });
    },
    currentPageChange(e) {
      this.param.queryRequest.pageNum = e;
      this.initData();
    },
    search() {
      this.param.queryRequest.pageNum = 1;
      this.initData();
    },
    resetSearchCotnet() {
      //重置搜索条件
      this.param.data.skuName = "";
      this.param.data.stTime = "";
      this.param.data.byTime = "";
      this.createdateList = [];
    }
  },
  watch: {}
};
</script>
<style scoped>
</style>